package pw.yumc.Residence.listeners;

import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.InventoryHolder;

import pw.yumc.Residence.gui.GuiHolder;
import pw.yumc.Residence.gui.SetFlag;

public class ResidenceGUIListener implements Listener {
    @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
    public void onFlagGuiClick(final InventoryClickEvent event) {
        final String player = event.getWhoClicked().getName();
        InventoryHolder guiHolder = event.getInventory().getHolder();
        if (guiHolder instanceof GuiHolder) {
            event.setCancelled(true);
            final int slot = event.getRawSlot();
            if ((slot > 53) || (slot < 0)) { return; }
            final SetFlag setFlag = ((GuiHolder) guiHolder).getFlag();
            setFlag.toggleFlag(event);
        }
    }
}
